<%@ page import="java.util.Vector" %>
<%@ page import="com.entity.Drug" %>
<%--
  Created by IntelliJ IDEA.
  User: 95241
  Date: 2021/9/21
  Time: 16:18
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>取药记录</title>

    <link rel="stylesheet" type="text/css" href="css/deal.css">

    <script type="text/javascript" src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
    <script type="text/javascript" >
        //排序
        //参数说明：conlNo:是按照哪一列进行排序从0开始计算的
        //        index：是第几个tbody标签 如果这个页面只有1个表那就是0 ，这个也是从0开始计算
        function sortTable (colNo,index) {
            //var isSort = [false,false,true];//标记是否排过序
            var rowsArray = [];//表格中所有行的集合
            var colsArray = [];//表格中所有列的集合
            //选中要排序的表
            var tbody = document.getElementsByTagName('tbody')[index];
            //初始化行和列
            for (var i = 0; i < tbody.rows.length; i++) {
                rowsArray[i] = tbody.rows[i];
                colsArray[i] = rowsArray[i].cells[colNo];
                //console.log(typeof(colsArray[i]));

            }
            //排序
            colsArray.sort(function (a,b) {
                return b.innerHTML - a.innerHTML;//将被点的那一列降序排序
            });
            colsArray.reverse();

            for (var i = 0; i < tbody.rows.length; i++) {
                console.log(rowsArray[i]);
            }
            //当某一列排序后将表格所有元素的值放到新的数组中
            var rowsTempArray = [];
            for (var i = 0; i < rowsArray.length; i++) {
                var colsTempArray = [];

                //console.log(colsArray.length)
                //console.log("列数")
                //tbody.rows[0].cells.length  获取列的长度
                for (var j = 0; j < tbody.rows[0].cells.length; j++) {
                    //将i行的所有列的内容保存在colsTempArray[j]中
                    //console.log(colsArray[i].parentNode.cells[j]);
                    colsTempArray[j] = colsArray[i].parentNode.cells[j].innerHTML;;
                }
                //将一行内容保存到rowsTempArray。
                rowsTempArray[i] = colsTempArray;
            }
            //重绘页面
            for (var i = 0; i < rowsArray.length; i++) {
                for (var j = 0; j < tbody.rows[0].cells.length; j++) {
                    rowsArray[i].cells[j].innerHTML = rowsTempArray[i][j];
                }
            }
        }

    </script>


</head>
<body style="background-color: #EBECF0">
<br>
<br>

<h2 style="margin-left: 15%">取药记录</h2>
<br>

<hr align=center width="70%" SIZE=3>
<br>
<br>

<center>
    <table border="1" cellspacing="0" width=70% cellpadding="20" id="returnFilterTab" class="table table-bordered">
        <tr bgcolor="#a9a9a9">
            <th align="center">编号</th>
            <th align="center">药品名</th>
            <th align="center">数量</th>
            <th align="center">诊断单ID</th>
        </tr>

        <%
            Vector<Drug> drugs = (Vector<Drug>) request.getAttribute("patientDrugs");
            Drug drug;
            if(drugs!=null){
                int index =1;
                int size = drugs.size();
                while (size>0){
                    drug = drugs.get(size-1);
                    if(drug!=null){
        %>
        <tr>
            <td align="center"><%=drug.getId()%></td>
            <td align="center"><%=drug.getDrugName()%></td>
            <td align="center"><%=drug.getNumber()%></td>
            <td align="center"><%=drug.getDiagnoseId()%></td>
        </tr>
        <%
        }
        else
        %>
        <%
                    size -= 1;
                }
            }
        %>
    </table>

    <br>
    <br>
    <a href="patientServlet?operation=homePage"><input type="button" value="返回" class="sub"></a>
</center>


</body>
</html>
